package com.glorysoft.wangnianxinpda.base;

import android.app.Activity;
import android.content.Context;
import android.view.KeyEvent;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.Button;
import android.widget.TextView;

import androidx.fragment.app.FragmentManager;

import com.glorysoft.wangnianxinpda.R;
import com.pda.platform.ui.ui_pdaplatform.base.FreeUI_BaseActivity;
import com.pda.platform.ui.ui_pdaplatform.callback.FreeUI_CommonCallback;
import com.pda.platform.ui.ui_pdaplatform.dialog.FreeUI_GeneralFragmentDialog;
import com.pda.platform.ui.ui_pdaplatform.entity.FreeUI_AddViewEntity;
import com.pda.platform.ui.ui_pdaplatform.utils_public.FreeApi_DialogUtils;

/**
 * @Author Zhangjy
 * @Date 2021/6/28 17:20
 * Description :
 */
public class BaseActivity extends FreeUI_BaseActivity {
    private FreeUI_GeneralFragmentDialog alertDialog = null;

    @Override
    protected int getLayoutResId() {
        return 0;
    }

    @Override
    protected void initView() {

    }

    @Override
    protected void initData() {

    }

    @Override
    protected FreeUI_AddViewEntity getBaseEntity() {
        return null;
    }

    protected void showBackDialog(Context context) {
        FreeApi_DialogUtils.getConfirmAndCancelDialog(this, "确定要退出当前界面吗？", ((Activity) context)::finish, () -> {
        }).show(getSupportFragmentManager(), "DIALOG");
    }

    protected void showDialog(String message, Boolean result) {
        alertDialog = new FreeUI_GeneralFragmentDialog();
        View view = LayoutInflater.from(App.app).inflate(R.layout.dialog_prompt, null);
        TextView tv = view.findViewById(R.id.tvTips);
        Button btnConfirm = view.findViewById(R.id.btnConfirm);
        btnConfirm.setOnClickListener(v -> alertDialog.dismiss());

        tv.setText(message);
        alertDialog.setLayout(view);
        alertDialog.show(getSupportFragmentManager(), "prompt");
        alertDialog.setCallBack(() -> alertDialog = null);
    }

    @Override
    public boolean onKeyDown(int keyCode, KeyEvent event) {
        if (keyCode == KeyEvent.KEYCODE_BACK) {
            showBackDialog(this);
            return false;
        } else {
            return super.onKeyDown(keyCode, event);
        }
    }


}
